// OnStyle
//
// Copyright (c)  Daigo Tanaka
// 
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// 
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
// 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.

onStyle.designer = function(main)
{
var private = {};


//
// Const methods
//
this.getTotalHeight = function(element)
{
  elementExpert = main.getElementExpert();
  if (!element.style) return;

  var count = 0;
  var height = parseInt(element.style.height);
  if (element.hasChildNodes()){
    var children = element.childNodes;
    for (var childIndex = 0; childIndex < children.length; childIndex++){
      if (children[childIndex].nodeName == "DIV" && elementExpert.isEditable( children[childIndex] ) != "" && children[childIndex].style){
        var currentHeight = parseInt(children[childIndex].style.top) + parseInt(children[childIndex].style.height);
        if (currentHeight > height) height = currentHeight;
      }
    }
  }
  return height;
};


this.getTotalWidth = function(element)
{
  elementExpert = main.getElementExpert();
  if (!element.style) return;

  var count = 0;
  var width = parseInt(element.style.width);
  if (element.hasChildNodes()){
    var children = element.childNodes;
    for (var childIndex = 0; childIndex < children.length; childIndex++){
      if (children[childIndex].nodeName == "DIV" && elementExpert.isEditable( children[childIndex] ) != "" && children[childIndex].style){
        var currentWidth = parseInt(children[childIndex].style.left) + parseInt(children[childIndex].style.width);
        if (currentWidth > width) width = currentWidth;
      }
    }
  }
  return width;
};

this.updateElementPositionAndSize = function()
{
  var elementExpert = main.getElementExpert();
  selectedElement = elementExpert.getSelectedElement();
  if (!selectedElement) return;
  if (selectedElement.style){
    var x = document.getElementById(onStyle.PosXID).value;
    var y = document.getElementById(onStyle.PosYID).value;
    var w = document.getElementById(onStyle.WidthID).value;
    var h = document.getElementById(onStyle.HeightID).value;
    selectedElement.style.top = y + "px";
    selectedElement.style.left = x + "px";
    selectedElement.style.width = w + "px";
    selectedElement.style.height = h + "px";
  }
};

this.pushDownElement = function()
{
  var elementExpert = main.getElementExpert();
  var selectedElement = elementExpert.getSelectedElement();

  if (!selectedElement) return;
  if (selectedElement.style){
    selectedElement.style.zIndex -= 1;
    if (selectedElement.style.zIndex < 1) selectedElement.style.zIndex = 1;
  }
};

};


